#-*- coding: utf-8 -*-
__author__ = 'lieber'

import os,sys
import codecs
import configparser
currentUrl = os.path.dirname(__file__)
proDir = os.path.abspath(os.path.join(currentUrl, os.pardir))
sys.path.append(proDir)
configPath = os.path.join(proDir, "config" ,"config.ini")


class ReadConfig:
    def __init__(self):
        fd = open(configPath)
        data = fd.read()

        #  remove BOM
        if data[:3] == codecs.BOM_UTF8:
            data = data[3:]
            file = codecs.open(configPath, "w")
            file.write(data)
            file.close()
        fd.close()

        self.cf = configparser.ConfigParser()
        self.cf.read(configPath)

    def get_email(self, name):
        value = self.cf.get("EMAIL", name)
        return value

    def get_http(self, name):
        value = self.cf.get("HTTP", name)
        return value

    def get_db(self, name):
        value = self.cf.get("DATABASE", name)
        return value
if __name__ == '__main__':
    print(configPath)